package com.cykj.dto;


public class ResponseDTO {
    private Integer code; // 响应状态
    private String msg;   // 响应消息
    private Object data;  // 响应数据


    private static final Integer SUCCESS = 200; // 成功
    private static final Integer ERROR = 404;   // 失败

    public ResponseDTO(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public ResponseDTO() {
    }
    // 成功响应
    public static ResponseDTO success(String msg, Object data) {
        return new ResponseDTO(SUCCESS, msg, data);
    }
    // 成功响应
    public static ResponseDTO success(String msg) {
        return new ResponseDTO(SUCCESS, msg, null);
    }

    // 失败响应
    public static ResponseDTO error(String msg) {
        return new ResponseDTO(ERROR, msg, null);
    }

    @Override
    public String toString() {
        return "ResponseDTO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
